using System.Text;

namespace System.Collections.Generic
{
    public static class DictionaryExtensions
    {
        public static string ToString<TKey, TValue>(this Dictionary<TKey, TValue> dictionary)
        {
            if (dictionary == null)
            {
                return "null";
            }

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("{ ");
            foreach (var kvp in dictionary)
            {
                stringBuilder.Append($"{kvp.Key}: {kvp.Value}, ");
            }
            if (dictionary.Count > 0)
            {
                stringBuilder.Remove(stringBuilder.Length - 2, 2);
            }
            stringBuilder.Append(" }");
            return stringBuilder.ToString();
        }

        public static Dictionary<TKey, TValue> Clone<TKey, TValue>(this Dictionary<TKey, TValue> dictionary)
        {
            return new Dictionary<TKey, TValue>(dictionary);
        }

        public static Dictionary<TKey, TValue> ConvertToDictionary<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary)
        {
            return new Dictionary<TKey, TValue>(dictionary);
        }
    }
}
